using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace UM_Model.Models.Mapping
{
    public class NewsMap : EntityTypeConfiguration<News>
    {
        public NewsMap()
        {
            // Primary Key
            this.HasKey(t => t.NewsID);

            // Properties
            this.Property(t => t.Title)
                .HasMaxLength(200);

            this.Property(t => t.Thumbnail)
                .HasMaxLength(200);

            // Table & Column Mappings
            this.ToTable("News");
            this.Property(t => t.NewsID).HasColumnName("NewsID");
            this.Property(t => t.Title).HasColumnName("Title");
            this.Property(t => t.Thumbnail).HasColumnName("Thumbnail");
            this.Property(t => t.Content).HasColumnName("Content");
            this.Property(t => t.TimePosted).HasColumnName("TimePosted");
            this.Property(t => t.IsTop).HasColumnName("IsTop");
            this.Property(t => t.Author).HasColumnName("Author");
            this.Property(t => t.Topic).HasColumnName("Topic");
            this.Property(t => t.IsEnable).HasColumnName("IsEnable");

            // Relationships
            this.HasOptional(t => t.Topic1)
                .WithMany(t => t.News)
                .HasForeignKey(d => d.Topic);

        }
    }
}
